package com.maybach.core.manager.impl;

import com.maybach.common.model.CarDO;
import com.maybach.common.query.CarQuery;
import com.maybach.core.dal.mapper.ext.CarExtMapper;
import com.maybach.core.manager.CarManager;
import com.maybach.util.query.support.PageResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * Manager for Car.
 */

@Component
public class CarManagerImpl implements CarManager{
    protected Logger log = LoggerFactory.getLogger(this.getClass());

    
    @Autowired
    protected CarExtMapper carExtMapper;
    /**
     * query count by query condition.
     */
    @Override
    public int countByQuery(CarQuery query){
        return carExtMapper.countByQuery(query);
    }

    /**
     * delete by query condition.
     */
    @Override
    public int deleteByQuery(CarQuery query){
        return carExtMapper.deleteByQuery(query);
    }

    /**
     * delete by primary key.
     */
    @Override
    public int deleteByPrimaryKey(CarDO record){
        return carExtMapper.deleteByPrimaryKey(record);
    }

    /**
     * insert selective.
     */
    @Override
    public long insertSelective(CarDO record){
        return carExtMapper.insertSelective(record);
    }

    /**
     * select by query condition.
     */
    @Override
    public List<CarDO> selectByQuery(CarQuery query){
        return carExtMapper.selectByQuery(query);
    }

    /**
     * select by query condition with page.
    */
    @Override
    public PageResult<CarDO> selectByQueryWithPage(CarQuery query) {
        PageResult<CarDO> result = new PageResult<CarDO>();
        result.setPageSize(query.getPageSize());
        result.setPageNo(query.getPageNo());
        result.setTotalCount(this.countByQuery(query));
        result.setResult(this.selectByQuery(query));
        return result;
    }

    /**
     * select by primary key.
     */
    @Override
    public CarDO selectByPrimaryKey(Long id){
        return carExtMapper.selectByPrimaryKey(id);
    }

    /**
     * update by query condition selective.
     */
    @Override
    public int updateByQuerySelective( CarDO record,  CarQuery query){
        return carExtMapper.updateByQuerySelective(record,  query);
    }

    /**
     * update by query condition.
     */
    @Override
    public int updateByQuery( CarDO record,  CarQuery query){

        return carExtMapper.updateByQuery(record, query);
    }

    /**
     * update by primary key selective.
     */
    @Override
    public int updateByPrimaryKeySelective(CarDO record){
        return carExtMapper.updateByPrimaryKeySelective(record);
    }
}